import Vue from 'vue'
import VueRouter from 'vue-router'
import AuthModule from 'views/login/login.js'
const authModule = new AuthModule()


Vue.use(VueRouter)

// CS:GO盲盒  路由: /csgGoBox 默认路由
const csgGoBox = () => import('views/cs-go-box/cs-go-box')
// 幸运饰品   路由: /luckyOrnament
const luckyOrnament = () => import('views/lucky-ornament/lucky-ornament')
// 免费皮肤   路由: /gratisSkin
const gratisSkin = () => import('views/gratis-skin/gratis-skin')
// data2盲盒  路由: /dota2Box
const dota2Box = () => import('views/dota2-box/dota2-box')
// 饰品商城   路由: /mall
const mall = () => import('views/mall/mall')
// 饰品背包   路由: /user/withdraw
const withdraw = () => import('views/withdraw/withdraw')
// 充值       路由: /user/payment
const payment = () => import('views/payment/payment')
// 我的帐单   路由: /user/transactions
const transactions = () => import('views/transactions/transactions')
// 推广中心   路由: /user/referral
const referral = () => import('views/referral/referral')
// 个人中心   路由: /user/center
const user = () => import('views/user/user')
// 消息通知   路由: /user/notices
const notices = () => import('views/notices/notices')


const routes = [
  {
    path: '/',
    redirect: '/csgGoBox'
  },
  {
    path: '/csgGoBox',
    component: csgGoBox,
  },
  {
    path: '/luckyOrnament',
    component: luckyOrnament,
    children: []
  },
  {
    path: '/gratisSkin',
    component: gratisSkin,
    children: []
  },
  {
    path: '/dota2Box',
    component: dota2Box,
    children: []
  },
  {
    path: '/mall',
    component: mall
  },
  {
    path: '/user/withdraw',
    component: withdraw,
    meta: { requiresAuth: true }
  },
  {
    path: '/user/payment',
    component: payment,
    meta: { requiresAuth: true }
  },
  {
    path: '/user/transactions',
    component: transactions,
    meta: { requiresAuth: true }
  },
  {
    path: '/user/referral',
    component: referral,
    meta: { requiresAuth: true }
  },
  {
    path: '/user/center',
    component: user,
    meta: { requiresAuth: true }
  },
  {
    path: '/user/notices',
    component: notices,
    meta: { requiresAuth: true }
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!authModule.verify()) {
      authModule.open()
    } else {
      next()
    }
  } else {
    next() // 确保一定要调用 next()
  }
})

export default router
